<template>
  <div class="sort-container">
    <h2>排序集合</h2>
  </div>
</template>

<script setup lang="ts">
// import { ref, reactive } from 'vue'

// type CommonArray<T> = T[]
let i = 0
// 快速排序
const quickSort = <T extends {}>(arr: T[]): T[] => {
  i++
  if (arr.length <= 1) return arr
  const mid = Math.floor(arr.length / 2)
  const midValue = arr.splice(mid, 1)[0]
  const left = []
  const right = []
  console.log(i, 'iiiiiiiiii', arr, mid, midValue)
  for (let index = 0; index < arr.length; index++) {
    arr[index] < midValue ? left.push(arr[index]) : right.push(arr[index])
  }

  return quickSort(left).concat(midValue, quickSort(right))
}
const arr = [5, 13, 15, 2, 1, 7, 10, 6]

onMounted(() => {
  console.log(quickSort<number>(arr))
})
</script>

<style lang="scss" scoped>
.sort-container {
}
</style>
